package org.example.Day5;

import java.util.Iterator;
import java.util.List;
import java.util.ArrayList;

public class List2 {
    public static void main(String[] args) {


        List<String> list = new ArrayList<>();
        list.add("蜘蛛精");
        list.add("⾄尊宝");
        list.add("糖宝宝");
        //1.普通for循环
        for (int i = 0; i < list.size(); i++) {
        //i = 0, 1, 2
        String e = list.get(i);
        System.out.println(e);
        }
        //2.增强for遍历
        for (String s : list) {
        System.out.println(s);
        }
        //3.迭代器遍历
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
        String s = it.next();
        System.out.println(s);
        }
        //4.lambda表达式遍历
        list.forEach(s -> System.out.println(s));
    }
}

